#####################################################################
# Product:      KnowledgeEngine (Plone Edition)
#
# File:         Service.py
#
# Copyright:    Copyright (c) 2004, Faulkner Technologies
#
# Author:       Brian Oliver
#
# Description:  Defines an abstract service object that may be 'looked up'
#               to provide 'services' to parts of the KnowledgeEngine.
#
#               An example implementation of this class is
#               the MySQLAssessmentStorageService, that is based on
#               the AssessmentStorageService - a specialised service
#               that handles the storage of assessments.
#
#               NOTE: Services are typically implemented as
#               'Plone Tools'
#
# See Also:     (none)
#####################################################################

#####################################################################
## KnowledgeEngine Library Imports
from Common import *

#####################################################################
## Zope Library Imports
from AccessControl import ClassSecurityInfo
from AccessControl.Role import RoleManager
from OFS.SimpleItem import SimpleItem
from OFS.PropertyManager import PropertyManager
from Products.CMFCore.utils import UniqueObject
from Products.CMFCore.permissions import ManagePortal
from Products.CMFCore.utils import getToolByName
from Globals import InitializeClass, DTMLFile, MessageDialog

#####################################################################
## Python Library Imports
# (none)

#####################################################################
## ServiceInfo Class Definition
class ServiceInfo(RoleManager):
    """
        Defines the service meta-information
    """

    #declare security so ClassInfo may be accessed in DTML/ZPT etc
    security = ClassSecurityInfo()
    security.declareObjectPublic()
    security.setDefaultAccess("allow")

    #---------------------------------------------------------------#

    # FINAL: A reference to the actual python Class instance.
    #        (Python represents actual classes as objects.  Hence
    #         class implementations may be modified at runtime
    #         simply by modifying the class instances)
    #
    # Automatically set when a class is registered with registerServiceClass
    classReference = None

    #---------------------------------------------------------------#

    def getClass(self):
        """
            FINAL: Return a reference to the actual class
        """

        return self.classReference

    #---------------------------------------------------------------#

    def getClassName(self):
        """
            Returns the name of the class for which
            we are providing information.
        """
        return 'Service'


    #---------------------------------------------------------------#

    def getDisplayName(self):
        """
            Return a friendly name for the services instances
        """

        return "Service"


    #---------------------------------------------------------------#

    def getServiceName(self):
        """
            ABSTRACT: Return the lookup-identity.

            This method must be overriden to provide a unique service name
            (this name is used to set the zope id of the service
            when created)
        """

        return "service"

#####################################################################
## Service Class Definition
class Service(UniqueObject, SimpleItem, PropertyManager):
    """
        Defines an abstract service that may be looked-up to provide
        KnowledgeEngine services.
    """

    #---------------------------------------------------------------#

    #ABSTRACT TRANSIENT: a ServiceInfo implementation instance to provide info about this service
    _SERVICEINFO = ServiceInfo()

    #---------------------------------------------------------------#

    #ZOPE: provide security over services
    security = ClassSecurityInfo()

    #ZOPE: setup standard management tabs
    manage_options = PropertyManager.manage_options + SimpleItem.manage_options

    toolicon = 'Cache/Model_icon.gif'

    #---------------------------------------------------------------#

    def __init__(self):
        """
            Constructor for the object
        """

        #this is a stateless mix-in
        pass

    #---------------------------------------------------------------#

    def getServiceInfo(self):
        """
            Return the ServiceInfo instance for this service
        """

        return self._SERVICEINFO

    #---------------------------------------------------------------#

#####################################################################
## Class Initialisation
InitializeClass(ServiceInfo)

